package com.briup.codingFormat;

import java.io.UnsupportedEncodingException;

/**
 * @auther thb
 * @date 2021/9/13
 */
public class CodingFormat {

    public static void main(String[] args) throws UnsupportedEncodingException {
        String str = "我们是中国人";
        System.out.println(str);
        String gbk_utf8_str = new String(str.getBytes("GBK"),"UTF-8");
        System.out.println(gbk_utf8_str);
        String gbk_utf8_gbk_str = new String(gbk_utf8_str.getBytes(),"GBK");
        System.out.println(gbk_utf8_gbk_str);
        String gbk_utf8_gbk_utf8_str = new String(gbk_utf8_str.getBytes(),"UTF-8");
        System.out.println(gbk_utf8_gbk_utf8_str);

        System.out.println("=======================================");
        show();
    }

    public static void show() throws UnsupportedEncodingException {
        String srcString = "我们是中国人";

        String gbk2UtfString = new String(srcString.getBytes("GBK"), "UTF-8");

        System.out.println("GBK转换成UTF-8：" + gbk2UtfString);

        String gbk2Utf2GbkString = new String(gbk2UtfString.getBytes("UTF-8"), "GBK");

        System.out.println("GBK转换成UTF-8再转成GBK：" + gbk2Utf2GbkString);
    }
}